<?
	$sess = new Zend_Session_Namespace(CLU_NS);
?>

<div class="blog_friend">
	<div class="blog_friend_bar">
		<table border="0" cellpadding="0" cellspacing="0" width="200">
			<tbody>
				<tr>
    				<td width="124"><?=t(184)?></td>
    				<td width="76">
	    				<a href="#" style="font-family: Arial,Helvetica,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; color: rgb(255, 255, 255);">
	    					<?=t(457)?>
	    				</a>&nbsp;
	    				<img src="/public/themes/hard/images/blog_bullet_edit.jpg" align="absmiddle">
    				</td>
  				</tr>
			</tbody>
		</table>
	</div>
	<br>	
	<div class="blog_friend_content">
		<div>
			<form id="new-comment-box" accept-charset="UTF-8" action="/<?=$sess->viewLang?>/comment/ajax/new-comment" method="post" >
				<input class = "submit_button" type="submit" style="display:none" ></input> <!-- style="display:none"-->
				<input type="hidden" name="poster_id" value="<?=$sess->userId?>" />
				<input type="hidden" name="content_poster_id" value="<?=$this->viewParams['content_id']?>" />
				<input type="hidden" name="content_id" value="<?=$this->viewParams['content_id']?>" />
				<input type="hidden" name="content_type" value="<?=$this->viewParams['content_type']?>" />
				<input type="hidden" name="region" value="<?=$this->viewParams['region']?>" />				
				<input type="hidden" name="type" value="user" />
				<?=$this->viewParams['form']->comment_text;?>
			</form>
		</div>
	</div>	
	
</div>
<div class="clear"></div>
<table border="0" cellpadding="0" cellspacing="0" width="233">
	<tbody><tr>
		<td width="128"></td>
		<td width="105"><div class="blog_left_content_joinfriend" align="center"><a href="javascript:void()" class = "submit_link"><?=t(172)?></a></div></td>
	 </tr>
	</tbody>
</table>
<div class="clear"></div>
<div class="blog_friend">
	<div class="blog_friend_content">
		<?$comments = $this->viewParams['comments'];?>
		<?for($i = 0;$i<min(5,count($comments));$i++){ ?>
			<div class = "box_comment_<?=$comments[$i]['id']?>">
				<div class="blog_friend_title"><a href="<?=$this->hvnUrl(array('action' => 'view'), 'account')?>?id=<?=$comments[$i]['poster_id']?>"><?=$comments[$i]['poster_name']?></a></div>
				<?
					$avatar = "/public/ufiles/" .$comments[$i]['poster_id'] . "/images/small/avatar/avatar.jpg";
					if (!file_exists(APP_PATH . $avatar))
					{
						$avatar = "/public/ufiles/0/images/small/avatar/avatar.jpg";
					}
				?>
				<div class="blog_friend_img"><a href="<?=$this->hvnUrl(array('action' => 'view'), 'account')?>?id=<?=$comments[$i]['poster_id']?>"><img src="<?=$avatar?>" align="absmiddle"></a></div>
			    <div class="text"><?=$comments[$i]['comment_text']?> </div>
				<div class="clear"></div>
				<div class="blog_time" align="right"><?=date('j/m/Y h:i:s A',$comments[$i]['created'])?> &nbsp;
					<?if (
			         		($sess->userId == $comments[$i]['poster_id'] && strpos($sess->userPermissions, 'delete own comment') )||  //commenter
			         		strpos($sess->userPermissions, 'delete comment') || //comment admin
			         		$sess->userId == $this->viewParams['content_id'] || //content owner TODO
			         		strpos($sess->userPermissions, 'administer ' . $this->viewParams['content_type']) //admin content
			                        ):
			        ?>
						<a href="javascript:void()" name="delete-comment-<?=$comments[$i]['id']?>-<?=$comments[$i]['poster_id']?>" >
							<img title="<?=t(31)?>" align="right" src="public/themes/hard/images/blog_delete.jpg"/>
						</a>
					<?endif?>
				</div>
			</div>
			
		<?}?>
		
	</div>	
</div>
<div class="clear"></div>
<br><br><br>
<script type="text/javascript">
$(function(){
	$("a.submit_link").click(function(){
		userId = <?=$sess->userId ?>;
		if (userId == 0 || userId == null)
		{
			alert('<?=t(6209) ?>');
			return false;
		}
	    var oEditor = FCKeditorAPI.GetInstance('comment_text') ;
	    $("#comment_text").val(oEditor.GetData()); 
		$("#new-comment-box").submit();
	});

	$("#new-comment-box").ajaxForm({
			dataType:  'json',
			success: function(json) {
				if (json.success)
				{
					alert("Thank you");
					window.location.reload();
				}
				else
				{
					alert(json.errorMessage);
				}
			}
		});

	$("a[name^=delete-comment]").click(function(){
		var del = confirm("Do you want to delete this comment?");
		deleteId = this.name.split('-')[2];
		posterId = this.name.split('-')[3];
		//alert(deleteId); del =0;
		if (del){	
			$.getJSON("/<?=$sess->viewLang?>/comment/ajax/delete-comment", {
				'id': deleteId,
				'poster_id': posterId,
				'content_id' : '<?=$this->viewParams['content_id']?>',
				'content_poster_id' : '<?=$this->viewParams['content_id']?>',
				'content_type' : '<?=$this->viewParams['content_type']?>',
				},
            function(json) {
                if(json.success){	
                	$(".box_comment_" + deleteId).css('background-color','red').fadeOut(2000);
 			    }                  
                else
                    $(".box_comment_" + deleteId).show().html("Could not delete");
                return false;
			});
		}else
			return false;
	});
});		
</script>
